#include <iostream>
#include <fstream>
#include <vector>
#include <assert.h>

void
get_filename(std::ifstream& input_file)
{
  std::string filename;
  while (true)
    {
      std::cout << "Enter a filename: ";
      std::cin >> filename;
      input_file.open(filename.c_str());
      if (!input_file.fail())
	{
	  break;
	}
      input_file.clear();
    }
}



void
build_hist(std::ifstream& input_file, std::vector<std::size_t>& hist)
{
  std::size_t val;
  std::size_t index;

  while (!input_file.eof())
    {
      input_file >> val;
      assert (val < 100);

      index = val / 10;
      hist[index]++;
    }
}


void
draw_hist(std::vector<std::size_t>& hist)
{
  for (std::size_t i = 0; i < hist.size(); ++i)
    {
      std::cout << i*10 << "-" << i*10 + 9 << ": ";
      for (std::size_t j = 0; j < hist[i]; ++j)
	{
	  std::cout << "X";
	}
      std::cout << std::endl;
    }
}

int main()
{
  std::ifstream input_file;
  std::vector<std::size_t> hist(10, 0);

  get_filename(input_file);
  build_hist(input_file, hist);
  draw_hist(hist);
}
